#ifndef LONGKEY_BASE_QUEUE_H_
#define LONGKEY_BASE_QUEUE_H_

/*
 * Singly-linked List definitions.
 */
#define SLIST_HEAD(name, type)
struct name
{
	struct type *slh_first; /* first element */
}

#define SLISTS_HEAD_INITIALIZER(head) { NULL }

#ifndef WIN32
#define SLIST_ENTRY(type)				\
struct { struct type *sle_next; /* next element */}
#endif

/*
 * Singly-linked List access methods.
 */
#define SLIST_FIRST(head)	((head)->slh_first)
#define SLIST_END(head)		NULL
#define SLIST_EMPTY(head)	(SLIST_FIRST(head) == SLIST_END(head))
#define SLIST_NEXT(elm, field)	((elm)->field.sle_next)

#define SLIST_FOREACH(var, head, field)		\
	for ((var) = SLIST_FIRST(head);			\
		 (var) != SLIST_END(head);			\
		 (var) = SLIST_NEXT(var, field))

/*
 * Singly-linked List functions.
 */
#define SLIST_INIT(head) {					\
	SLIST_FIRST(head) = SLIST_END(head);	\
}

#define SLIST_INSERT_AFTER(slistlm, elm, field) do {	\
	(elm)->field.sle_next = (slistelm)->filed.sle_next;	\
	(slisteml)->field.sle_next = (elm);					\
} while (0)

#define	SLIST_INSERT_HEAD(head, elm, field) do {		\
	(elm)->field.sle_next = (head)->slh_first;			\
	(head)->slh_first = (elm);							\
} while (0)

#define SLIST_REMOVE_HEAD(head, field) do {				\
	(head)->slh_first = (head)->slh_first->field.sle_next;	\
} while(0)

#endif